const express = require('express');
const router = express.Router();
const multiparty = require('multiparty');


router.all('/recognition',(req,res)=>{
  console.log("upload")
  // console.log(req)
  // console.log("上传图片分析")
  // res.header("Access-Control-Allow-Origin", "*");
  // res.header("Access-Control-Allow-Headers", "X-Requested-With");
  // res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  // res.header("X-Powered-By", ' 3.2.1')
  // res.header("Content-Type", "multipart/form-data");
  //注意：这里必须事先定义静态资源路径
  let form = new multiparty.Form({uploadDir:'upload_img'});
  //该模块主要是对前端传过来的file做一个formData的处理
  
  form.parse(req,(err,fields,file) => {
    if(err){
      res.json({
        "status":0,
        "msg":`上传失败,失败原因${err.message}`
      })
      return false;
    }
    console.log(fields)
    console.log(file)
    if(fields.type[0]=='mold_number'){
      res.send({
        "status": 0,
        "msg": "成功",
        "imageId":"1111",
        "textBlocks":[{'text':'235/45R18T05QAZ'}]
      })
    }else if(fields.type[0]=='mold_code'){
      res.send({
        "status": 0,
        "msg": "成功",
        "imageId":"1111",
        "textBlocks":[{'text':'235/45R18T05QAZ'}]
      })
    }else if(fields.type[0]=='dot'){
      res.send({
        "status": 0,
        "msg": "成功",
        "imageId":"1111",
        "textBlocks":[{'text':'DOT3323'}]
      })
    }else if(fields.type[0]=='tile'){
      res.send({
        "status": 0,
        "msg": "成功",
        "imageId":"1111",
        "textBlocks":[{'text':'555555'}]
      })
    }else{
      res.send({
        "status": 0,
        "msg": "成功",
        "imageId":"111",
        "textBlocks":[{'text':'444444'}]
      })
    }
    
  });
})
module.exports = router;